<%@ page language="java" pageEncoding="UTF-8"%>
<%@ page import="com.app.service.vo.UserVo"%>
<%@ page import="java.util.*"%>
<%@ page import="com.app.service.vo.RoleVo"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

<title>My JSP 'userbingrule.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<script type="text/javascript" src="../js/jquery-1.7.2.js"></script>
<script type="text/javascript">
	function manageDiv(src, rulename, ruleid) {
		var divplay = document.getElementById(src).style.display;
		if (divplay == "") {
			document.getElementById(src).style.display = "none";
		} else {
			document.getElementById(src).style.display = "";
			document.getElementById("ruleName").innerHTML = "<b>角色名："
					+ rulename + "</b>";
			document.getElementById("ruleid").value = ruleid;
			var checkeds = document
									.getElementsByName("userid");
			for(var i=0;i<checkeds.length;i++)
			{
				checkeds[i].checked=false;
			}
			$.ajax({
			url : "<%=request.getContextPath()%>/ajax.form",
						type : 'POST',
						data : "ruleid=" + ruleid + "&key=r-u-checked",
						dataType : 'json',
						async : false,
						contentType : "application/x-www-form-urlencoded; charset=utf-8",
						timeout : 3000,
						error : function(XMLHttpRequest, textStatus,
								errorThrown) {

							alert('Error ' + XMLHttpRequest + textStatus
									+ errorThrown);
						},
						success : function(result) {
							var arg = result["checkeds"];
							
							for ( var i = 0; i < arg.length; i++) {

								for ( var j = 0; j < checkeds.length; j++) {

									if (arg[i] == checkeds[j].value) {
										checkeds[j].checked=true;

									}
								}
							}
						}
					});
			
		}

	}
</script>
</head>

<body>

	<table width="95%">
		<tr>
			<td>角色名</td>
			<td>角色描述</td>
			<td>操作</td>
		</tr>
		<%
			List<RoleVo> list = (List<RoleVo>) request
					.getAttribute("rule-list");
			for (RoleVo vo : list) {
		%>
		<tr>
			<td><%=vo.getName()%></td>
			<td><%=vo.getRolesDescription()%></td>
			<td><a
				href="javaScript:manageDiv('rulediv','<%=vo.getName()%>','<%=vo.getId()%>')">绑定用户</a>
			</td>
		</tr>

		<%
			}
		%>
	</table>

	<hr>
	<div id="rulediv" style="display:none">
		<span id="ruleName"></span>
		<form action="<%=request.getContextPath() %>/admin/rulebing.form" method="post">
		<table width="95%">
			<tr>
				<td>用户名</td>
				<td>真实姓名</td>
				<td>操作</td>

			</tr>
			<%
				List<UserVo> uservolist = (List<UserVo>) request
						.getAttribute("user-list");
				if (null != uservolist) {
					for (UserVo vo : uservolist) {
			%>
			<tr>
				<td><%=vo.getUsername()%></td>
				<td><%=vo.getName()%></td>
				<td>绑定<input type="checkbox" name="userid" value="<%=vo.getId()%>" />
				</td>
			</tr>
			<%
				}
				}
			%>
		</table>
		<input type="hidden" name="ruleid" id="ruleid" /> <input type="submit"
			value="确认绑定" />
			</form>
	</div>
</body>
</html>
